/*
 *  powerup.cpp
 *  
 *
 *  Created by Nicholas Blecha on 11/29/10.
 *  Copyright 2010 Michigan Technological University. All rights reserved.
 *
 */

#include "powerup.h"

Powerup::Powerup(Renderer* rend) {
	rnd = rend;
	images[HEALTH] = rnd->loadImage("Images//powerup1.png");
	images[SHIELD] = rnd->loadImage("Images//powerup2.png");
	images[MISSILE] = rnd->loadImage("Images//MisslePowerup.png");
	texIDs[HEALTH] = rnd->createTexture(images[HEALTH]);
	texIDs[SHIELD] = rnd->createTexture(images[SHIELD]);
	texIDs[MISSILE] = rnd->createTexture(images[MISSILE]);
	
	drawPos = new SDL_Rect();
	
	hidden=true;

	hitbox = new Hitbox(28, 32, 20, 22);
        hitbox->setIdentifier("Powerup");
	radius = 25;
}

void Powerup::init(int t, int x, int y) {
	image = images[t];
	texId = texIDs[t];
	
	type = t;
	
	position.x = x;
	position.y = y;
	drawPos->w = position.w = image->w;
	drawPos->h = position.h = image->h;
	
	hidden=false;
}

bool Powerup::isHidden() {
	return hidden;
}

void Powerup::hide() {
	hidden=true;
}

void Powerup::show(int mapX, int mapY) {
	drawPos->x=position.x-mapX;
	drawPos->y=position.y-mapY;
	rnd->drawSurface(drawPos, angle, texId);
}

void Powerup::collect(Fighter* target) {
	switch (type) {
		case HEALTH:
			target->dmg(-(target->getMaxHP()/4));
			break;
		case SHIELD:
			target->setShielded(true);
			break;
		case MISSILE:
			dynamic_cast<SpecialAttack*>(target->getSpecialAttack())->addUses(2);
			break;

		default:
			break;
	}
	hidden=true;
}

Powerup::~Powerup() {
	delete hitbox;
	for (int x=0; x<3; x++) {
		SDL_FreeSurface(images[x]);
	}
	if (drawPos!=NULL) {
		delete drawPos;
	}
}
